package 第一章基础算法.区间合并.id803区间合并;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 贪心
 */
public class Main {
    public static void main(String[]args){
        //处理输入
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        //保存所有区间
        int[][] segments = new int[n][2];
        for(int i = 0;i<n;i++){
            segments[i][0] = scanner.nextInt();
            segments[i][1] = scanner.nextInt();
        }
        //区间升序排序
        Arrays.sort(segments,(int[]o1,int[]o2)->{
            if(o1[0] == o2[0])return o1[1] - o2[1];
            return o1[0] - o2[0];
        });
        int start = segments[0][0];
        int end = segments[0][1];
        int res = 1;
        //遍历区间
        for(int i = 1;i<n;i++){
            if(segments[i][0] > end){
                res++;
                start = segments[i][0];
                end = segments[i][1];
            }else {
                end = Math.max(end,segments[i][1]);
            }
        }
        System.out.println(res);
    }
}
